/* wintapi.h */

/********************/
/* TAPI-INTERFACE   */
/* for MS-Windows   */
/* (C) 2003 by NAH6 */
/********************/

#ifndef __WINTAPI_H
#define __WINTAPI_H
#ifdef __cplusplus
extern "C" {
#endif

/*------------*/
/*  INCLUDES  */
/*------------*/

#include <windows.h>
#include <tapi.h>

/*-----------*/
/*  DEFINES  */
/*-----------*/

#define E_TAPI_NULLPTR            (-0x5201)
#define E_TAPI_NOMEM              (-0x5202)
#define E_TAPI_DLLINIT            (-0x5203)
#define E_TAPI_DLLVER             (-0x5204)
#define E_TAPI_TSPINIT            (-0x5205)
#define E_TAPI_TSPVER             (-0x5206)
#define E_TAPI_LINENUM            (-0x5207)
#define E_TAPI_LINECAPS           (-0x5208)
#define E_TAPI_LINESTAT           (-0x5209)
#define E_TAPI_ADRNUM             (-0x520A)
#define E_TAPI_ADRCAPS            (-0x520B)
#define E_TAPI_ADRSTAT            (-0x520C)
#define E_TAPI_LINEOPEN           (-0x520D)
#define E_TAPI_MSGMASK            (-0x520E)
#define E_TAPI_LINECLOSE          (-0x520F)
#define E_TAPI_LINESHUTDOWN       (-0x5210)
#define E_TAPI_GETMSG             (-0x5211)
#define E_TAPI_CALLINFO           (-0x5212)
#define E_TAPI_CALLSTAT           (-0x5213)
#define E_TAPI_ACCEPT1            (-0x5214)
#define E_TAPI_ACCEPT2            (-0x5215)
#define E_TAPI_NORING             (-0x5216)
#define E_TAPI_ANSWER1            (-0x5217)
#define E_TAPI_ANSWER2            (-0x5218)
#define E_TAPI_LINKSERV           (-0x5219)
#define E_TAPI_LINKCARR           (-0x521A)
#define E_TAPI_MAKECALL1          (-0x521B)
#define E_TAPI_MAKECALL2          (-0x521C)
#define E_TAPI_GETPORT            (-0x521D)
#define E_TAPI_CALLCLOSE          (-0x521E)
#define E_TAPI_CALLDROP           (-0x521F)
#define E_TAPI_CALLDEALLOC        (-0x5220)
#define E_TAPI_BREAK              (-0x5221)
#define E_TAPI_CALL_TIMEOUT       (-0x5222)
#define E_TAPI_CALL_UNKNOWN       (-0x5223)
#define E_TAPI_CALL_HANGUP        (-0x5224)
#define E_TAPI_CALL_PICKUP        (-0x5225)
#define E_TAPI_CALL_FORWARDED     (-0x5226)
#define E_TAPI_CALL_DIALTONE      (-0x5227)
#define E_TAPI_CALL_OUTOFORDER    (-0x5228)
#define E_TAPI_CALL_TEMPFAILURE   (-0x5229)
#define E_TAPI_CALL_CONGESTION    (-0x522A)
#define E_TAPI_CALL_BADADDRESS    (-0x522B)
#define E_TAPI_CALL_NUMCHANGED    (-0x522C)
#define E_TAPI_CALL_UNREACHABLE   (-0x522D)
#define E_TAPI_CALL_INCOMPATIBLE  (-0x522E)
#define E_TAPI_CALL_NOANSWER      (-0x522F)
#define E_TAPI_CALL_BUSY          (-0x5230)
#define E_TAPI_CALL_BLOCKED       (-0x5231)
#define E_TAPI_CALL_REJECT        (-0x5232)
#define E_TAPI_CALL_DISTURB       (-0x5233)

/*====*/

#define K_TAPI_APPNAME        "SPcore"
#define K_TAPI_MINTSPVER      (0x00010003L)
#define K_TAPI_MINDLLVER      (0x00020000L)
#define K_TAPI_MAXVER         (TAPI_CURRENT_VERSION)

#define K_TAPI_MAXLINES                (16)
#define K_TAPI_MAXADR                  (16)
#define K_TAPI_PARBLKLEN             (4096)
#define K_TAPI_DIALNUMBUFLEN           (64)

#define K_TAPI_CHKTIME                (100)
#define K_TAPI_RDTIMEOUT                (5)
#define K_TAPI_DIALINTIMEOUT           (60)
#define K_TAPI_DIALOUTTIMEOUT         (120)

/*----*/

#define K_TAPI_DEVICE_NOHW           (0x00)
#define K_TAPI_DEVICE_OK             (0x01)
#define K_TAPI_DEVICE_ERROR          (0xFF)

#define K_TAPI_CALLSTATE_IDLE           (0)
#define K_TAPI_CALLSTATE_RINGING        (1)
#define K_TAPI_CALLSTATE_CONNECTING     (2)
#define K_TAPI_CALLSTATE_CONNECTED      (3)

#define K_TAPI_MSG_NONE                 (0)
#define K_TAPI_MSG_RINGOFF              (1)
#define K_TAPI_MSG_RINGON               (2)
#define K_TAPI_MSG_RINGING              (3)

#define K_TAPI_WINMSG_NONE              (0)
#define K_TAPI_WINMSG_OFFER             (1)
#define K_TAPI_WINMSG_REPLY             (2)
#define K_TAPI_WINMSG_LINEDEVSTATE      (3)
#define K_TAPI_WINMSG_ADDRESSSTATE      (4)
#define K_TAPI_WINMSG_CALLINFO          (5)
#define K_TAPI_WINMSG_CALLSTATE         (6)
#define K_TAPI_WINMSG_UNKNOWN           (7)

/*----*/

#define K_TAPI_LINKSERVICES             (3)
#define K_TAPI_LINKSERVICE_DATA         (0)
#define K_TAPI_LINKSERVICE_FAX          (1)
#define K_TAPI_LINKSERVICE_VOICE        (2)
#define K_TAPI_LINKSERVICE_UNKNOWN   (0xFF)

#define K_TAPI_LINKCARRIERS             (2)
#define K_TAPI_LINKCARRIER_DIG          (0)
#define K_TAPI_LINKCARRIER_ANA          (1)
#define K_TAPI_LINKCARRIER_UNKNOWN   (0xFF)

/*--------------*/
/*  STRUCTURES  */
/*--------------*/

struct tapi_hwinfo_line
{
  unsigned char valid;
  DWORD         tspapi;
  LINEDEVCAPS  *caps;
};

struct tapi_hwinfo_adr
{
  unsigned char    valid;
  LINEADDRESSCAPS *caps;
};

/*--*/

struct tapi_hwinfo
{
  DWORD  dllapi;
  struct tapi_hwinfo_line line[K_TAPI_MAXLINES];
  struct tapi_hwinfo_adr  adr [K_TAPI_MAXLINES][K_TAPI_MAXADR];
};

struct tapi_config
{
  volatile unsigned char *sigterm;
  unsigned char line;
  unsigned char adr;
};

struct tapi_data
{
  /* Config-Info */
  struct tapi_config cfg;

  /* Line-Info */
  DWORD               dllapi;
  DWORD               tspapi;
  HLINEAPP            happ;
  HANDLE              tevt;
  HLINE               hline;
  LINEDEVCAPS        *lcaps;
  LINEADDRESSCAPS    *acaps;
  LINEDEVSTATUS      *lstat;
  LINEADDRESSSTATUS  *astat;

  /* Call-Info */
  unsigned char       callstate;
  unsigned char       service;
  HCALL               hcall;
  LINECALLINFO       *cinfo;
  LINECALLSTATUS     *cstat;
  DWORD               mlstat;
  DWORD               mcstat;
  DWORD               mcsdet;
  HANDLE              iochan;
  DWORD               jobid;
  LONG                result;
  LINEMESSAGE         lmsg;
};

/*--*/

struct tapi_link
{
  unsigned char dialout;
  unsigned char remnumlen;
  unsigned char remnumbuf[K_TAPI_DIALNUMBUFLEN];
  unsigned char service;
  unsigned char carrier;
  unsigned long baudrate;
};

/*--------------*/
/*  PROTOTYPES  */
/*--------------*/

void tapi_hwdetect_create  (struct tapi_hwinfo *info);
void tapi_hwdetect_destroy (const struct tapi_hwinfo *info);
void tapi_hwautocfg        (struct tapi_config *config, \
                            const struct tapi_hwinfo *info);

signed short tapi_open  (struct tapi_data *dseg, const struct tapi_config *cfg);
signed short tapi_close (struct tapi_data *dseg);

signed short tapi_watch   (struct tapi_data *dseg, struct tapi_link *link);
signed short tapi_connect (struct tapi_data *dseg, struct tapi_link *link);
signed short tapi_hangup  (struct tapi_data *dseg);


#ifdef __cplusplus
}
#endif
#endif


/*** EOF ***/
